       
                         X Performance Considerations

   
     o  Scalable Fonts, don't use them unless you are scaling them.
        Otherwise use pre-built bitmap fonts.
   
     o  Avoid non-rectangular window clips.  Exposes involve more 
        events;  rendering is less efficient.
   
     o  Avoid the SHAPE extension.  It complicates clip regions.
   
     o  Avoid asking for MotionNotify events on windows.  Wakes your 
        client when pointer moves through your windows.
   
     o  Avoid backing store.
   
     o  Be careful about leaking pixmaps.  This ends up growing the 
        X server's heap.
   
     o  Be aware of the small cost associated with GC validation costs. 
        Example:
   
        /* GC validation per primative */
        for(i=0;i<100;i++) {
            DrawPrimitive(drawableA, GC);
            DrawPrimitive(drawableB, GC);
        }

        /* more efficient */
        for(i=0;i<100;i++)
            DrawPrimitive(drawableA, GC);
        for(i=0;i<100;i++)
            DrawPrimitive(drawableB, GC);
   
     o  Take advantage of Xlib's automatic poly-primitive request 
        batching.  Example:
   
        for(i=0;i<100;i++)
            XDrawLine(dpy,drawable,gc, x1[i],y1[i],x2[i],y2[i]);
   
        This become one PolySegement request.  
        Rules:  Can't change drawable or gc;  
                can't interleave other requests.
   
     o  Be sure to compress expose events.  Toolkits normally do this 
        for you.
   
     o  Use MapNotify and VisibilityNotify events to stop animation or 
        continous screen update.
   
     o  Map child windows, then parent window.
   
     o  When doing CopyArea or CopyPlane from a drawable you know is a 
        pixmap, be sure the GC has GCGraphicsExpose set to False.  
        Otherwise you are generating useless NoExpose events.
   
     o  Understand XSync vs. XFlush.  XFlush makes sure all pending X 
        requests are sent to X server for execution in finite time.  
        XSync ensures all requests have been executed, forcing a 
        round-trip.
   
     o  If you design benchmarks involving X, consider X latency.  
        Measure how much work actually gets done, not how much work can 
        be queued.  Use XSync to ensure benchmark completion.
   
     o  Don't use unnecessarily deep visuals;  image data and pixmaps 
        need to be just as deep.
   
     o  Don't use Xlib, Xt, or Motif routines in a signal handler.  Set a 
        global variable and get out.
   
     o  The X server is not an inter-process communication clearing house.
        Properties, atoms, and selections are very inefficient for 
        communicating data between clients.
   
     o  Use pixie's call counting to determine what X or Xt routines you 
        are calling a lot.  Set dbx breakpoints; find out why.
   
     o  When changing cursor to busy cursor, let subwindows inherit new 
        cursor from parents instead of changing the cursor for each window.
   
     o  X round-trip hit list.  Is there a good reason for calling these 
        routines?
   
     XAllocColor            XGetModifierMapping    XQueryTree
     XAllocColorCells       XGetWindowProperty     XSync
     XAllocColorPlanes      XGetWindowAttributes   XTranslateCoordinates
     XAllocNamedColor       XQueryFont             XInternAtom 
     XGetAtomName           XQueryBestSize         XListFonts 
     XGetGeometry           XQueryColor            XListFontsWithInfo
     XGetKeyboardMapping    XQueryColors           
     
     
     
     
